//获取账号名称节点
var per = document.querySelector('.list1').children[0].lastElementChild;
//获取cookie
var n1=getCookie('name');
//账号显示
if(n1){
  per.innerHTML = n1;
  per2.innerHTML = n1+",你好";
}else{
  per.innerHTML = '亲，请登录';
}
//跳转购物车
var car = document.querySelector('.list2').children[1]
    car.onclick=function(){
      if(n1){
        location="../06shopcar/shopcar.html"
      }else{
        alert("您还未登陆，请注册或登录")
        // location="../02login/login.html"
      }
    }
//获取input框和按钮
var inps = document.querySelectorAll('input')
var btn = document.querySelector('button')
console.log(inps,btn);

inps[3].onclick=function(){
    if(this.checked){
        btn.disabled=false
        btn.style. opacity="1"
    }else{
        btn.disabled=true
        btn.style. opacity=".5"
    }
}

let form = $("form");
let id =$("#id");
let username = $("#username");
let password = $("#password");
var search = location.search

//表单验证
$("form").validate({
    rules: {
        id: {
            required: true,
            rangelength: [1, 5],
        },
        username: {
            required: true,
            rangelength: [2, 5],
        },
        password: "required",
    },
    messages: {
        id: {
            required: "编号是必填的",
            rangelength: "编号的长度必须在1-5之间",
        },
        username: {
            required: "用户名是必填",
            rangelength: "用户名的长度必须在2-5之间",
        },
        password: "密码是必填",
    },
    submitHandler: async function () {
        let e = window.event;
        e.preventDefault();

        var txt=await PromiseAjax({
            url:'./zhuce.php',
            data:`id=${id.val()}&name=${username.val()}&pass=${password.val()}`
        })
        console.log(txt);
        if(txt==0){
            alert("注册成功")
            location="../02login/login.html"
        }else{
            alert("该用户已注册，请重新注册")
            location.reload()
        }
    },
});
